package org.charles.zhifou.model.vo;

import cn.hutool.json.JSONUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.charles.zhifou.model.entity.ScoringResult;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 评分结果视图
 *
 * @author charles
 * @version 1.0
 */
@Data
public class ScoringResultVO implements Serializable {

    @Schema(description = "id")
    private Long id;

    @Schema(description = "结果名称，如物流师")
    private String resultName;

    @Schema(description = "结果描述")
    private String resultDesc;

    @Schema(description = "结果图片")
    private String resultPicture;

    @Schema(description = "结果属性集合 JSON，如 [I,S,T,J]")
    private List<String> resultProp;

    @Schema(description = "结果得分范围，如 80，表示 80及以上的分数命中此结果")
    private Integer resultScoreRange;

    @Schema(description = "应用 id")
    private Long appId;

    @Schema(description = "创建用户 id")
    private Long userId;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Schema(description = "创建用户信息")
    private UserVO user;

    /**
     * 封装类转对象
     *
     * @param scoringResultVO
     * @return
     */
    public static ScoringResult voToEntity(ScoringResultVO scoringResultVO) {
        if (scoringResultVO == null) {
            return null;
        }

        ScoringResult scoringResult = new ScoringResult();
        BeanUtils.copyProperties(scoringResultVO, scoringResult);
        // 将答案转成 JSON 字符串
        scoringResult.setResultProp(JSONUtil.toJsonStr(scoringResultVO.getResultProp()));

        return scoringResult;
    }

    /**
     * 对象转封装类
     *
     * @param scoringResult
     * @return
     */
    public static ScoringResultVO entityToVo(ScoringResult scoringResult) {
        if (scoringResult == null) {
            return null;
        }

        ScoringResultVO scoringResultVO = new ScoringResultVO();
        BeanUtils.copyProperties(scoringResult, scoringResultVO);
        // 将答案转成 List
        scoringResultVO.setResultProp(JSONUtil.toList(scoringResult.getResultProp(), String.class));

        return scoringResultVO;
    }
}
